import 'dart:async';

import 'package:flutter/material.dart';
import 'package:loadmore/KLoadMore.dart';
import 'package:loadmore/loadmore.dart';
import 'package:loadmore/progress.dart';

void main() => runApp(new MyApp2());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    print("_datas.length = ${_datas.length}");
    return new MaterialApp(
      theme: new ThemeData(
        primaryColor: Colors.green,
      ),
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('我的内容'),
        ),
        body: new LoadMore(
          child: _buildListView(),
          onRefresh: _onRefresh,
        ),
      ),
    );
  }

  Future<Null> _onRefresh() async {
    var future = new Completer().future;
    new Timer(new Duration(seconds: 3), () {
      future.then((value) {
        print("$value");
      }).whenComplete(() {
        print("whenComplete");
      });
    });
  }
}

_buildListView() {
  return new ListView.builder(
    itemCount: _datas.length,
    itemBuilder: (BuildContext context, int index) {
      return new Column(
        children: <Widget>[
          new ListTile(
            title: new Text(_datas[index]),
          ),
          new Divider(
            color: Colors.black,
            height: 0.5,
            indent: 16.0,
          ),
        ],
      );
    },
  );
}

var _datas = new List<String>.generate(12, generator);

String generator(int index) {
  return index.toString();
}

class MyApp2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        body: new ProgressWidget(),
      ),
    );
  }
}

class MyApp3 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(),
        body: new LoadMoreIndicator(
          child: _buildListView(),
          onRefresh: () {},
        ),
      ),
    );
  }
}
